<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>付款单登记表新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">付款单信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">登记公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="hrOrgId" value="${bindOrgId}">
					      		<input type="hidden" name="id" value="${payBill.id}">
								<input type="text" value="${bindOrgName}" style="border:0px;width:220px" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">登记部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">登记人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					    	<label class="layui-form-label">付款业务来源</label>
				      		<div class="layui-input-inline">
				        		<infopub:select name="fromType" value="${payBill.fromType }" disabled="disabled" type="dic" groupNo="A00010067"></infopub:select>
				      		</div>
				    	</div>
		    			<div class="layui-inline">
					    	<label class="layui-form-label">付款公司</label>
				      		<div class="layui-input-inline">
						    	<c:choose>
						    		<c:when test="${payBill.fromType == '1' or payBill.fromType == '4' }">
						        		<select name="hrOrgBillId" lay-verify="required"  lay-search>
						        			<option value="">请选择-付款公司</option>
						              		<c:if test="${not empty orgInfos }">
						              			<c:forEach items="${orgInfos}" var="org">
						              				<option value="${org.id }">${org.compName }</option>
							            		</c:forEach>
						              		</c:if>
						              	</select>
						    		</c:when>
						    		<c:otherwise>
				    					<input type="hidden" name="hrOrgBillId" value="${orgInfo.id }">
				    					<input type="text" value="${orgInfo.compName }" style="border:0px" readonly="readonly" class="layui-input">
						    		</c:otherwise>
						    	</c:choose>
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">付款归属项目</label>
				      		<div class="layui-input-inline">
		    					<input type="hidden" name="proCode" value="${payBill.proCode }">
		    					<input type="text" name="proName" value="${payBill.proName }" style="border:0px" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					    	<label class="layui-form-label">结算方式</label>
				      		<div class="layui-input-inline">
				        		<infopub:select id="add-form-settle" entireName="-结算方式" name="settlementMode" layVerify="required" type="dic" groupNo="A00010063"></infopub:select>
				      		</div>
					    </div>
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">付款日期</label>
				      		<div class="layui-input-inline">
				      			<input type="text" class="layui-input" id="sent-laydate-pay" name="payDate" lay-verify="required" readonly>
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					    	<label class="layui-form-label">应付总额（元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" name="willPayAmount" value="${payBill.willPayAmount }" style="border:0px" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">实付总额（元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" name="actPayAmount" style="border:0px" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">付款摘要</label>
				      		<div class="layui-input-inline">
				      			<textarea name="paySummary" maxlength="50" placeholder="请输入付款摘要" lay-verify="required" class="layui-textarea" style="width:899px;min-height:50px;"></textarea>
				      		</div>
					    </div>
				    </div>
		  		</div>
			</fieldset>
			<c:choose>
				<c:when test="${payBill.fromType == '3' }">
					<fieldset class="layui-elem-field layui-field-title fieldset"  id="detailInfo">
				  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">申请还款明细 ></legend>
					  	<div style="margin-top:20px">
					  		<div class="layui-form-item" style="margin: 0 20px;">
					  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
				                  	<thead>
				                    	<tr>
				                      		<th>序号</th>
				                      		<th>还款对象单位</th>
				                      		<th>还款类型</th>
					                      	<th>还款金额（元）</th>
					                      	<th>实付金额（元）</th>
					                      	<th>支出类型</th>
					                    </tr> 
				                  	</thead>
				                  	<tbody>
			                  		<c:forEach items="${payBill.payBillDetails }" var="detail" varStatus="status">
						  				<tr>
				                      		<td>${status.count }<input type="hidden" name="payBillDetails[${status.index }].id" value="${detail.id}"></td>
				                      		<td>${detail.accountName }</td>
				                      		<td>${detail.repayType == '1' ? '归还本金':'支付利息'}</td>
				                      		<td>${detail.applyAmount }</td>
				                      		<td>
					                      		<div class="layui-input-inline">
					                      			<input type="text" name="payBillDetails[${status.index }].actPayAmount" lay-verify="required|floatAmount" onblur="calcSumAmount()" class="layui-input">
					                      		</div>
				                      		</td>
				                      		<td>
				                      			<div class="layui-input-inline">
				                      				<infopub:select entireName="-支出类型" name="payBillDetails[${status.index }].payOutType" layVerify="required" type="dic" groupNo="A00010068" laySearch="true"></infopub:select>
				                      			</div>
				                      		</td>
				                    	</tr>
									</c:forEach>
				                  	</tbody>
									<tfoot>
					                    <tr>
					                      <td>合计</td>
					                      <td></td>
					                      <td></td>
					                      <td>${payBill.willPayAmount }</td>
					                      <td id="actPayAmount"></td>
					                      <td></td>
					                    </tr>
				                  	</tfoot>
			                  	</table>
		                  	</div>
					  	</div>
					</fieldset>
				</c:when>
				<c:when test="${payBill.fromType == '5' }">
					<fieldset class="layui-elem-field layui-field-title fieldset"  id="detailInfo">
				  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">申请税费明细 ></legend>
					  	<div style="margin-top:20px">
					  		<div class="layui-form-item" style="margin: 0 20px;">
					  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
				                  	<thead>
				                    	<tr>
				                      		<th>序号</th>
				                      		<th>税费类型</th>
					                      	<th>是否费用化</th>
					                      	<th>税费金额（元）</th>
					                      	<th>实付金额（元）</th>
					                      	<th>支出类型</th>
					                    </tr> 
				                  	</thead>
				                  	<tbody>
			                  		<c:forEach items="${payBill.payBillDetails }" var="detail" varStatus="status">
						  				<tr>
				                      		<td>${status.count }<input type="hidden" name="payBillDetails[${status.index }].id" value="${detail.id}"></td>
				                      		<td>
												<div class="layui-input-inline">
				                      				<infopub:select value="${detail.taxType }" name="taxType" disabled="disabled" type="dic" groupNo="A00010065"></infopub:select>
				                      			</div>
											</td>
											<td>
					                      		<div class="layui-input-inline">
					                      			<select name="payBillDetails[${status.index }].countFlag" lay-verify="required">
					                      				<option value="">请选择-是否费用化</option>
					                      				<option value="1">是</option>
					                      				<option value="0">否</option>
					                      			</select>
					                      		</div>
				                      		</td>
				                      		<td>${detail.applyAmount }</td>
				                      		<td>
					                      		<div class="layui-input-inline">
					                      			<input type="text" name="payBillDetails[${status.index }].actPayAmount" lay-verify="required|floatAmount" onblur="calcSumAmount()" class="layui-input">
					                      		</div>
				                      		</td>
				                      		<td>
				                      			<div class="layui-input-inline">
				                      				<infopub:select entireName="-支出类型" name="payBillDetails[${status.index }].payOutType" layVerify="required" type="dic" groupNo="A00010068" laySearch="true"></infopub:select>
				                      			</div>
				                      		</td>
				                    	</tr>
									</c:forEach>
				                  	</tbody>
									<tfoot>
					                    <tr>
					                      <td>合计</td>
					                      <td></td>
					                      <td></td>
					                      <td>${payBill.willPayAmount }</td>
					                      <td id="actPayAmount"></td>
					                      <td></td>
					                    </tr>
				                  	</tfoot>
			                  	</table>
		                  	</div>
					  	</div>
					</fieldset>
				</c:when>
				<c:otherwise>
					<fieldset class="layui-elem-field layui-field-title fieldset"  id="detailInfo">
				  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">申请付款明细 ></legend>
					  	<div style="margin-top:20px">
					  		<div class="layui-form-item" style="margin: 0 20px;">
					  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
				                  	<thead>
				                    	<tr>
				                      		<th>序号</th>
				                      		<th>支付对象单位</th>
					                      	<th>申请付款金额（元）</th>
					                      	<th>实付金额（元）</th>
					                      	<th>支出类型</th>
					                    </tr> 
				                  	</thead>
				                  	<tbody>
			                  		<c:forEach items="${payBill.payBillDetails }" var="detail" varStatus="status">
						  				<tr>
				                      		<td>${status.count }<input type="hidden" name="payBillDetails[${status.index }].id" value="${detail.id}"></td>
				                      		<td>${detail.accountName }</td>
				                      		<td>${detail.applyAmount }</td>
				                      		<td>
					                      		<div class="layui-input-inline">
					                      			<input type="text" name="payBillDetails[${status.index }].actPayAmount" lay-verify="required|floatAmount" onblur="calcSumAmount()" class="layui-input">
					                      		</div>
				                      		</td>
				                      		<td>
				                      			<div class="layui-input-inline">
				                      				<infopub:select entireName="-支出类型" name="payBillDetails[${status.index }].payOutType" layVerify="required" type="dic" groupNo="A00010068" laySearch="true"></infopub:select>
				                      			</div>
				                      		</td>
				                    	</tr>
									</c:forEach>
				                  	</tbody>
									<tfoot>
					                    <tr>
					                      <td>合计</td>
					                      <td></td>
					                      <td>${payBill.willPayAmount }</td>
					                      <td id="actPayAmount"></td>
					                      <td></td>
					                    </tr>
				                  	</tfoot>
			                  	</table>
		                  	</div>
					  	</div>
					</fieldset>
				</c:otherwise>
			</c:choose>
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-pay'
    });
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
  	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/payBill/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/payBill/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '付款单登记表';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/payBill/sign';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
	
	//计算费用总额
	function calcSumAmount(){
		var $ = layui.$;
		var totalAmount = 0;
  		$("input[name$='.actPayAmount']").each(function(){
			var tId = $(this).val();
			if(tId != '' && parseFloat(tId) > 0){
				totalAmount = totalAmount + parseFloat(tId);
			}
		});
  		$("input[name=actPayAmount]").val(totalAmount.toFixed(2));
  		$("#actPayAmount").html(totalAmount.toFixed(2));
	}
  </script>
</body>
</html>

